forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: auto-switch to imported mode with architect fallback #9003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daniel-lxs
wants to merge
11
commits into
main
Choose a base branch
from
feat/auto-switch-imported-mode-with-architect-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: auto-switch to imported mode with architect fallback #9003
daniel-lxs
wants to merge
11
commits into
main
from
feat/auto-switch-imported-mode-with-architect-fallback
+209
−4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes [#8239](#8239) ## Summary Automatically switches to the imported mode after a successful mode import, providing immediate feedback and eliminating the need for manual mode selection. ## Changes ### Backend (CustomModesManager.ts) - Modified `importModeWithRules()` to return the imported mode's slug in the result - Returns `{ success: true, slug: importData.customModes[0]?.slug }` on success - Enables the UI to know which mode was imported for automatic switching ### Message Handler (webviewMessageHandler.ts) - Updated `importMode` case to handle the new slug return value - Passes the slug to the webview via `importModeResult` message - Maintains backward compatibility with existing error handling ### UI (ModesView.tsx) - Added auto-switch logic in `importModeResult` message handler - Attempts to find imported mode in fresh customModes list - Falls back to direct slug-based switch if mode not yet in list - Updates visual mode state for immediate UI feedback - Only switches on success with a valid slug provided ### Tests (ModesView.import-switch.spec.tsx) - Added new test suite for import auto-switch behavior - Tests successful switch when slug is provided - Tests no-switch behavior on import failure or missing slug - Verifies both backend message and UI state updates ## Testing - New test coverage added for auto-switch scenarios - Existing import/export functionality remains unchanged - Works with both global and project-level imports
…tener Use a stable ref to hold the latest switchMode and avoid capturing it in the window "message" listener closure: Add a switchModeRef updated via useEffect; call switchModeRef.current in the importModeResult fallback instead of switchMode Mirrors existing handleModeSwitchRef/customModesRef pattern to keep handler stable while accessing fresh values Prevents re-registration churn and removes the ESLint warning with no runtime behavior change File touched: webview-ui/src/components/modes/ModesView.tsx Why: The effect that registers the window event listener intentionally has an empty dependency array; directly referencing switchMode violates react-hooks/exhaustive-deps. Using a ref decouples the effect from function identity changes while preserving up-to-date behavior.
Type safety for slug Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
…rt success updateCustomMode() was catching and swallowing all errors, causing importModeWithRules() to return success even when mode persistence failed. This led to auto-switch attempting to activate modes that never persisted.
…rt' of https://github.com/heyseth/Roo-Code into feat/auto-switch-to-imported-mode-after-successful-import
Moves type declaration out of event handler to prevent redeclaration on every message event.
…ejections while allowing importModeWithRules to detect persistence failures
…issues - Use parseYamlSafely() in importModeWithRules for consistent YAML parsing across the codebase, ensuring BOM stripping and character cleaning - Sync visualMode with context.mode to prevent UI desync when modes are switched programmatically from outside the component - Add test coverage for fallback branch when imported mode slug is not yet present in customModes state Fixes parser inconsistency (P2), visualMode desync risk (P3), and missing test coverage (P3) identified in code review.
Based on PR #8521 by @heyseth (Seth Miller) with the following enhancements: Original work by Seth Miller: - Auto-switch to imported mode after successful import - Backend returns imported mode slug in importModeWithRules() - UI switches to imported mode when found in customModes list - Comprehensive test coverage for auto-switch functionality Additional improvements: - Use architect mode as fallback when imported slug not yet present - Updated test to expect architect mode in fallback scenario - Prevents UI desync during state refresh race conditions Co-authored-by: Seth Miller <[email protected]>
Review CompleteLatest commit (387acca) reviewed - no issues found. The change improves code maintainability by replacing hardcoded "architect" strings with The implementation remains well-structured:
Mention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request. |
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
PR - Needs Review
size:L
This PR changes 100-499 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Supersedes PR #8521 by @heyseth (Seth Miller) with additional enhancement.
Description
This PR implements automatic switching to newly imported modes with an improved fallback mechanism.
Original work by @heyseth (Seth Miller):
importModeWithRules()Additional enhancement:
Implementation Details
Backend Changes:
CustomModesManager.ts: Returns imported mode slug for UI auto-switchwebviewMessageHandler.ts: Passes slug to UI on successful importUI Changes:
ModesView.tsx: Auto-switches to imported mode when found, falls back to architect mode when slug not yet in stateModesView.import-switch.spec.tsx: Tests cover success, fallback, and failure scenariosTest Procedure
Automated Tests
Manual Testing Steps
Same as original PR #8521:
Co-authored-by
Co-authored-by: Seth Miller [email protected]
Important
This PR adds auto-switching to imported modes with a fallback to architect mode, including backend, UI changes, and tests.
CustomModesManager.ts: Returns imported mode slug inimportModeWithRules().webviewMessageHandler.ts: Sends imported mode slug to UI.ModesView.tsx: Switches to imported mode or falls back to architect mode.ModesView.import-switch.spec.tsx: Tests for auto-switch, fallback, and failure scenarios.This description was created by
for 387acca. You can customize this summary. It will automatically update as commits are pushed.